package org.sluggard.tangela.core;

import java.io.IOException;
import java.util.Map;

import javax.swing.JFrame;

public class Container {
	
	private static Map<String, Token> map;
	
	private static MainFrameView mainSelf;
	
	static JFrame tempFrame = new JFrame();
	
	private static TokenStore tokenStore;
	
	static {
		try {
			tokenStore = new TokenStore();
			map = tokenStore.load();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void send(String message) {
		for(Token token : map.values()) {
			if(token.isState()) {
				token.sendMessage(message);
			}
		}
	}
	
	public static void addToken(Token token) {
		map.put(token.getName(), token);
		try {
			tokenStore.save(map);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Token getToken(String name) {
		return map.get(name);
	}

	static MainFrameView getMainSelf() {
		return mainSelf;
	}

	static void setMainSelf(MainFrameView mainSelf) {
		Container.mainSelf = mainSelf;
	}
	
}
